home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 436_01 / addattr.asm < prev    next >
Assembly Source File  |  1994-10-07  |  4KB  |  80 lines

  1. ;==========================================================================
  2. ; ADDATTR.ASM
  3. ;
  4. ;    Assembler:     Turbo Assembler 1.0 (tasm /ml/t/w2/z addattr;)
  5. ;  C prototype:
  6. ; void pascal far addattr
  7. ;             (
  8. ;      char far     *DestBuf,           /* receiving buffer              */
  9. ;      char far     *SrcBuf,            /* text buffer                   */
  10. ;      char far     *AttrList,          /* list of attribute bytes       */
  11. ;           int      ListSize,          /* length of AttrList            */
  12. ;           int      Attr,              /* default attribute             */
  13. ;           int      Flag               /* mark attribute changes        */
  14. ;             )     ;
  15. ;
  16. ; INCON source files and the object and library files created from
  17. ; them are:
  18. ;    Copyright (c) 1993-94, Richard Zigler.
  19. ; You may freely distribute unmodified source, object, and library
  20. ; files, and incorporate them into your own non-commercial software,
  21. ; provided that this paragraph and the copyright string defined in
  22. ; INCON.C are included in all copies.
  23. ;==========================================================================
  24.  
  25.          .model     small, pascal
  26.           .code
  27.  
  28.          public     ADDATTR
  29.         ADDATTR     proc far
  30.            uses     si, di, ds, es
  31.  
  32.             arg     Flag:     word                ;mark attribute changes
  33.             arg     Attr:     word                ;default attribute
  34.             arg     ListSize: word                ;length of AttrList
  35.             arg     AttrList: far ptr byte        ;list of attributes
  36.             arg     SrcBuf:   far ptr byte        ;text buffer
  37.             arg     DestBuf:  far ptr byte        ;receiving buffer
  38.  
  39.             cld                                   ;do strings low-to-high
  40.             mov     cx, [ListSize]                ;get list size
  41.             les     di, [DestBuf]                 ;destination buffer
  42.  
  43. ; For this next to work, AttrList and SrcBuf must be in the same segment.
  44.  
  45.             lds     bx, [AttrList]      ;attribute list
  46.             lds     si, [SrcBuf]        ;source buffer
  47.             mov     dx, [Flag]          ;DL = flag character
  48.             mov     ah, byte ptr [Attr] ;default attribute
  49.            jcxz     NoAttr              ;if no AttrList
  50.             and     dl, dl
  51.              jz     NoAttr              ;if no flag char
  52. GetChar:
  53.           lodsb                         ;get character from SrcBuf
  54.             and     al, al
  55.              jz     Exit                ;if end of SrcBuf
  56.             cmp     al, dl
  57.              je     GotFlag             ;if flag character
  58.           stosw                         ;char/attr => DestBuf
  59.             jmp     GetChar
  60. GotFlag:
  61.           lodsb                         ;get next character
  62.             mov     ah, [bx]            ; and next attr byte
  63.           stosw                         ;char/attr => DestBuf
  64.             inc     bx
  65.            loop     GetChar             ;if at end of AttrList,
  66. NoAttr:                                 ; fall through
  67.           lodsb                         ;get character from SrcBuf
  68.             and     al, al
  69.              jz     Exit                ;if end of SrcBuf
  70.           stosw                         ;char/attr => DestBuf
  71.             jmp     NoAttr              ;if not end of SrcBuf
  72. Exit:
  73.             ret                         ;else done
  74.         ADDATTR     endp
  75.             end
  76.  
  77. ; EOF:  ADDATTR.ASM
  78.  
  79. 
  80.